<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.org/ui"
      xmlns:c="http://java.sun.com/jsp/jstl/core">

    <body>

        <ui:composition template="./productionReport.xhtml">

            <ui:define name="tabContent">
                <h:form>
                    Mạng
                    <p:selectManyCheckbox value="#{productionByServiceBean.selectedDeliverProvider}">
                        <f:selectItem itemLabel="Mobifone" itemValue="smsgate_mobifone"/>
                        <f:selectItem itemLabel="Vinaphone" itemValue="smsgate_vinaphone"/>
                        <f:selectItem itemLabel="Viettel" itemValue="smsgate_viettel"/>
                    </p:selectManyCheckbox>

                    <br/>

                    <p:selectOneRadio value="#{productionByServiceBean.reportType}">
                        <f:selectItem itemLabel="Theo tháng" itemValue="#{productionByServiceBean.BY_MONTH}"/>
                        <f:selectItem itemLabel="Theo ngày" itemValue="#{productionByServiceBean.BY_DAY}"/>
                        <f:selectItem itemLabel="Theo khung ngày" itemValue="#{productionByServiceBean.BY_DAY_RANGE}"/>
                        <f:selectItem itemLabel="Theo khung giờ" itemValue="#{productionByServiceBean.BY_HOUR_RANGE}"/>
                        <p:ajax event="change" update="byMonth byDay byDayRange byHourRange" process="@this"/>
                    </p:selectOneRadio>

                    <br/>
                    <h:panelGrid id="byMonth">
                        <h:panelGrid columns="10" rendered="#{productionByServiceBean.reportType == productionByServiceBean.BY_MONTH}">
                            Tháng
                            <p:selectOneMenu value="#{productionByServiceBean.month}">
                                <f:selectItem itemLabel="1" itemValue="1"/><f:selectItem itemLabel="2" itemValue="2"/>
                                <f:selectItem itemLabel="3" itemValue="3"/><f:selectItem itemLabel="4" itemValue="4"/>
                                <f:selectItem itemLabel="5" itemValue="5"/><f:selectItem itemLabel="6" itemValue="6"/>
                                <f:selectItem itemLabel="7" itemValue="7"/><f:selectItem itemLabel="8" itemValue="8"/>
                                <f:selectItem itemLabel="9" itemValue="9"/><f:selectItem itemLabel="10" itemValue="10"/>
                                <f:selectItem itemLabel="11" itemValue="11"/><f:selectItem itemLabel="12" itemValue="12"/>
                            </p:selectOneMenu>
                            Năm
                            <p:selectOneMenu value="#{productionByServiceBean.year}">
                                <f:selectItem itemLabel="2011" itemValue="2011"/>
                                <f:selectItem itemLabel="2012" itemValue="2012"/>
                                <f:selectItem itemLabel="2013" itemValue="2013"/>
                            </p:selectOneMenu>
                            <p:commandButton ajax="false" value="Xem báo cáo" action="#{productionByServiceBean.reportByMonth()}" onclick="processingDialog.show()"/>
                        </h:panelGrid>
                    </h:panelGrid>

                    <h:panelGrid id="byDay">
                        <h:panelGrid columns="10" rendered="#{productionByServiceBean.reportType == productionByServiceBean.BY_DAY}">
                            Ngày
                            <p:calendar value="#{productionByServiceBean.day}" pattern="dd/MM/yyyy" timeZone="Asia/Saigon" navigator="true"
                                        required="true" requiredMessage="Bạn chưa chọn ngày"/>
                            <p:commandButton ajax="false" value="Xem báo cáo" action="#{productionByServiceBean.reportByDay()}" onclick="processingDialog.show()"/>
                        </h:panelGrid>
                    </h:panelGrid>


                    <h:panelGrid id="byDayRange">
                        <h:panelGrid columns="4" rendered="#{productionByServiceBean.reportType == productionByServiceBean.BY_DAY_RANGE}">
                            Từ tháng
                            <p:selectOneMenu value="#{productionByServiceBean.startMonth}">
                                <f:selectItem itemLabel="1" itemValue="1"/><f:selectItem itemLabel="2" itemValue="2"/>
                                <f:selectItem itemLabel="3" itemValue="3"/><f:selectItem itemLabel="4" itemValue="4"/>
                                <f:selectItem itemLabel="5" itemValue="5"/><f:selectItem itemLabel="6" itemValue="6"/>
                                <f:selectItem itemLabel="7" itemValue="7"/><f:selectItem itemLabel="8" itemValue="8"/>
                                <f:selectItem itemLabel="9" itemValue="9"/><f:selectItem itemLabel="10" itemValue="10"/>
                                <f:selectItem itemLabel="11" itemValue="11"/><f:selectItem itemLabel="12" itemValue="12"/>
                            </p:selectOneMenu>
                            Năm
                            <p:selectOneMenu value="#{productionByServiceBean.startYear}">
                                <f:selectItem itemLabel="2011" itemValue="2011"/>
                                <f:selectItem itemLabel="2012" itemValue="2012"/>
                                <f:selectItem itemLabel="2013" itemValue="2013"/>
                            </p:selectOneMenu>


                            Đến tháng
                            <p:selectOneMenu value="#{productionByServiceBean.endMonth}">
                                <f:selectItem itemLabel="1" itemValue="1"/><f:selectItem itemLabel="2" itemValue="2"/>
                                <f:selectItem itemLabel="3" itemValue="3"/><f:selectItem itemLabel="4" itemValue="4"/>
                                <f:selectItem itemLabel="5" itemValue="5"/><f:selectItem itemLabel="6" itemValue="6"/>
                                <f:selectItem itemLabel="7" itemValue="7"/><f:selectItem itemLabel="8" itemValue="8"/>
                                <f:selectItem itemLabel="9" itemValue="9"/><f:selectItem itemLabel="10" itemValue="10"/>
                                <f:selectItem itemLabel="11" itemValue="11"/><f:selectItem itemLabel="12" itemValue="12"/>
                            </p:selectOneMenu>
                            Năm
                            <p:selectOneMenu value="#{productionByServiceBean.endYear}">
                                <f:selectItem itemLabel="2011" itemValue="2011"/>
                                <f:selectItem itemLabel="2012" itemValue="2012"/>
                                <f:selectItem itemLabel="2013" itemValue="2013"/>
                            </p:selectOneMenu>

                            <br/>

                            Khung ngày: từ ngày <p:inputText value="#{productionByServiceBean.startDay}" size="3"/>
                            đến ngày <p:inputText value="#{productionByServiceBean.endDay}" size="3"/>
                            <p:commandButton ajax="false" value="Xem báo cáo" action="#{productionByServiceBean.reportByDayRange()}" onclick="processingDialog.show()"/>
                        </h:panelGrid>
                    </h:panelGrid>



                    <h:panelGrid id="byHourRange">
                        <h:panelGrid columns="4" rendered="#{productionByServiceBean.reportType == productionByServiceBean.BY_HOUR_RANGE}">
                            Từ ngày 
                            <p:calendar value="#{productionByServiceBean.startDate}" pattern="dd/MM/yyyy" timeZone="Asia/Saigon" navigator="true"
                                        required="true" requiredMessage="Bạn chưa chọn ngày"/>
                            đến ngày
                            <p:calendar value="#{productionByServiceBean.endDate}" pattern="dd/MM/yyyy" timeZone="Asia/Saigon" navigator="true"
                                        required="true" requiredMessage="Bạn chưa chọn ngày"/>

                            <br/>

                            Khung giờ: từ <p:inputText value="#{productionByServiceBean.startHour}" size="3"/>
                            đến <p:inputText value="#{productionByServiceBean.endHour}" size="3"/>
                            <p:commandButton ajax="false" value="Xem báo cáo" action="#{productionByServiceBean.reportByHourRange()}" onclick="processingDialog.show()"/>
                        </h:panelGrid>
                    </h:panelGrid>
                </h:form>

                <br/>

                <h:form id="form">

                    <p:dataTable id="tblReportByMonth" rendered="#{productionByServiceBean.reportType == productionByServiceBean.BY_MONTH}"
                                 value="#{productionByServiceBean.singleReportModel}" var="item" resizableColumns="true">
                        <p:column headerText="Thời gian">
                            #{item.date}
                        </p:column>
                        <p:column headerText="S2">
                            <p:commandLink action="#{productionByServiceBean.viewServiceGroupDetail(item.date, 'S2')}" 
                                           update="form:detailTable form:detailDialog" onsuccess="detailDialog.show();">
                                #{item.s2Production}
                            </p:commandLink>
                        </p:column>
                        <p:column headerText="Base">
                            <p:commandLink action="#{productionByServiceBean.viewServiceGroupDetail(item.date, 'BASIC')}" 
                                           update="form:detailTable form:detailDialog" onsuccess="detailDialog.show();">
                                #{item.baseServiceProduction}
                            </p:commandLink>
                        </p:column>
                        <p:column headerText="TxtBase">
                            <p:commandLink action="#{productionByServiceBean.viewServiceGroupDetail(item.date, 'TXTBASE')}" 
                                           update="form:detailTable form:detailDialog" onsuccess="detailDialog.show();">
                                #{item.txtBaseProduction}
                            </p:commandLink>
                        </p:column>
                    </p:dataTable>

                    <p:dataTable id="tblReportByDay" rendered="#{productionByServiceBean.reportType == productionByServiceBean.BY_DAY}"
                                 value="#{productionByServiceBean.singleReportModel}" var="item" resizableColumns="true">
                        <p:column headerText="Thời gian">
                            #{item.date}
                        </p:column>
                        <p:column headerText="S2">
                            <p:commandLink action="#{productionByServiceBean.viewServiceGroupDetail(item.date, 'S2')}" 
                                           update="form:detailTable form:detailDialog" onsuccess="detailDialog.show();">
                                #{item.s2Production}
                            </p:commandLink>
                        </p:column>
                        <p:column headerText="Base">
                            <p:commandLink action="#{productionByServiceBean.viewServiceGroupDetail(item.date, 'BASIC')}" 
                                           update="form:detailTable form:detailDialog" onsuccess="detailDialog.show();">
                                #{item.baseServiceProduction}
                            </p:commandLink>
                        </p:column>
                        <p:column headerText="TxtBase">
                            <p:commandLink action="#{productionByServiceBean.viewServiceGroupDetail(item.date, 'TXTBASE')}" 
                                           update="form:detailTable form:detailDialog" onsuccess="detailDialog.show();">
                                #{item.txtBaseProduction}
                            </p:commandLink>
                        </p:column>
                    </p:dataTable>

                    <h:panelGrid columns="10" rendered="#{productionByServiceBean.reportType == productionByServiceBean.BY_DAY_RANGE}">

                        <table border="0">
                            <tr>
                                <ui:repeat value="#{productionByServiceBean.reportByDayRangeModel}" var="grandItem">
                                    <td>
                                        <p:dataTable value="#{grandItem.reportModels}" var="item" resizableColumns="true">
                                            <p:column headerText="Thời gian">
                                                #{item.date}
                                            </p:column>
                                            <p:column headerText="S2">
                                                <p:commandLink action="#{productionByServiceBean.viewServiceGroupDetail(item.date, 'S2')}" 
                                                               update="form:detailTable form:detailDialog" onsuccess="detailDialog.show();">
                                                    #{item.s2Production}
                                                </p:commandLink>
                                            </p:column>
                                            <p:column headerText="Base">
                                                <p:commandLink action="#{productionByServiceBean.viewServiceGroupDetail(item.date, 'BASIC')}" 
                                                               update="form:detailTable form:detailDialog" onsuccess="detailDialog.show();">
                                                    #{item.baseServiceProduction}
                                                </p:commandLink>
                                            </p:column>
                                            <p:column headerText="TxtBase">
                                                <p:commandLink action="#{productionByServiceBean.viewServiceGroupDetail(item.date, 'TXTBASE')}" 
                                                               update="form:detailTable form:detailDialog" onsuccess="detailDialog.show();">
                                                    #{item.txtBaseProduction}
                                                </p:commandLink>
                                            </p:column>
                                        </p:dataTable>
                                    </td>
                                </ui:repeat>
                            </tr>
                        </table>
                    </h:panelGrid>

                    <h:panelGrid columns="10" rendered="#{productionByServiceBean.reportType == productionByServiceBean.BY_HOUR_RANGE}">
                        <table border="0">
                            <tr>
                                <ui:repeat value="#{productionByServiceBean.reportByHourRangeModel}" var="grandItem" >
                                    <td>
                                        <p:dataTable value="#{grandItem.reportModels}" var="item" resizableColumns="true">
                                            <p:column headerText="Thời gian">
                                                #{item.date}
                                            </p:column>
                                            <p:column headerText="S2">
                                                <p:commandLink action="#{productionByServiceBean.viewServiceGroupDetail(item.date, 'S2')}" 
                                                               update="form:detailTable form:detailDialog" onsuccess="detailDialog.show();">
                                                    #{item.s2Production}
                                                </p:commandLink>
                                            </p:column>
                                            <p:column headerText="Base">
                                                <p:commandLink action="#{productionByServiceBean.viewServiceGroupDetail(item.date, 'BASIC')}" 
                                                               update="form:detailTable form:detailDialog" onsuccess="detailDialog.show();">
                                                    #{item.baseServiceProduction}
                                                </p:commandLink>
                                            </p:column>
                                            <p:column headerText="TxtBase">
                                                <p:commandLink action="#{productionByServiceBean.viewServiceGroupDetail(item.date, 'TXTBASE')}" 
                                                               update="form:detailTable form:detailDialog" onsuccess="detailDialog.show();">
                                                    #{item.txtBaseProduction}
                                                </p:commandLink>
                                            </p:column>
                                        </p:dataTable>
                                    </td>
                                </ui:repeat>
                            </tr>
                        </table>
                    </h:panelGrid>


                    <!-- History Dialog -->
                    <p:dialog id="diag" width="300" hideEffect="explode" widgetVar="detailDialog" 
                              header="Sản lượng chi tiết" >  
                        <!--                        <b>
                                                    Mạng:  <br/>
                                                    Thời gian: <br/>
                                                    Nhóm dịch vụ: <br/>
                                                </b>-->
                        <br/>

                        <p:dataTable  id="detailTable" value="#{productionByServiceBean.serviceGroupDetailList}" var="detailItem" >

                            <p:column headerText="Cú pháp" sortBy="#{detailItem.requestDetail}">
                                #{detailItem.requestDetail}
                            </p:column>
                            <p:column headerText="Sản lượng" sortBy="#{detailItem.production}">
                                #{detailItem.production}
                            </p:column>

                        </p:dataTable>
                        <p:commandButton value="Đóng" onclick="detailDialog.hide()" type="button" />   

                    </p:dialog> 
                </h:form>
            </ui:define>

        </ui:composition>

    </body>
</html>
